package com.tz.online.user.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tz.online.entity.User;
import com.tz.online.user.service.IUserService;
import com.tz.online.util.BeanFactory;

@WebServlet(name="validateName",urlPatterns="/user/validateName")
public class ValidateNameAction extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8339680437019338744L;
	//通过bean工厂，获得service接口对象
	IUserService us = (IUserService) BeanFactory.getBean("userService");
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		PrintWriter out = resp.getWriter();
		String name = req.getParameter("uname");
		//判断此用户是否存在
		User user = us.loginUser(name);
		if(user!=null){
			//存在返回1
			out.print("1");
		}else {
			//不存在返回0
			out.print("0");
		}
	}
}
